use ggez::{glam::Vec2, Context, graphics::{self, Rect}};



pub struct Particle {
    origin: Vec2,
    velocity: Vec2,
    acceleration: Vec2,

    size: Vec2,
    mass: f32,
    
    lifespan: f32
}

impl Particle {
    pub fn new(origin: Vec2, size: Vec2, velocity: Vec2) -> Particle {
        let acceleration = Vec2{x: 0.0, y: 0.05};
        let mass = 10.0;
        let lifespan = 1.0;
        Particle { origin, velocity, acceleration, size, mass, lifespan}
    }

    pub fn is_dead(&self) -> bool {
        if self.lifespan <= 0.0 {
            true
        } else {
            false
        }
    }

    pub fn get_mass(&self) -> f32 {
        self.mass
    }

    pub fn apply_force(&mut self, force: Vec2) -> () {
        self.acceleration += force;
    }

    pub fn update(&mut self) -> () {
        self.acceleration /= self.mass;
        self.velocity += self.acceleration;
        self.origin += self.velocity;
        self.lifespan -= 0.001;
        self.acceleration *= 0.0;
    }

    pub fn display(&self, ctx: &mut Context, canvas : &mut graphics::Canvas) -> () {

        let rect = graphics::Mesh::new_rectangle(
            ctx, 
            graphics::DrawMode::fill(), 
            Rect { x: self.origin.x, y: self.origin.y, w: self.size.x, h: self.size.y } , 
            graphics::Color::new(0.7, 0.7, 0.7, self.lifespan)).unwrap();
        canvas.draw(&rect, graphics::DrawParam::default()); 



    }
}